package A_review.review9_12;

import A_review.review9_4.QuickSortt;

public class QuickSort {


    public   int[] quickSort(int[] nums){

        if (nums.length==0){
            return null;
        }

        sort(nums,0, nums.length-1);

        return  nums;

    }

    public  void  sort(int[] nums,int lo,int hi){
        if (lo>=hi){
            return;
        }
        int part = part(nums, lo, hi);
        sort(nums, lo, part-1);
        sort(nums, part+1, hi);

    }

    public  int part(int[] nums,int lo,int hi){

        int part=nums[lo];
        int j=lo+1;
        int k=hi;
        while (j<=k&&j<=hi&&k>=0){
            while (nums[j]<part&&j<=hi){
                j++;
            }
            while (nums[k]>part&&k>=0){
                k--;
            }
            if (j>=k){
                break;
            }
            swap(nums,j,k);
        }
        swap(nums,lo,k);
        return  k;
    }

    public  void  swap(int[] nums,int j,int k){
        int temp=nums[j];
        nums[j]=nums[k];
        nums[k]=temp;
    }

    public static void main(String[] args) {
        QuickSort quickSort = new QuickSort();
        int[] arr={2,3,1,4,6,4,7,12};
        int[] ints = quickSort.quickSort(arr);
        for (int a:ints
        ) {
            System.out.println(a);

        }

    }
}
